From 17f91c37ba5a0f30c02b07546f138832f546e901 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Thu, 23 Feb 2006 14:37:51 +0000 Subject: [PATCH] (bug 4535) Warn user when editing CSS or JS subpage of a skin that doesn't exist --- RELEASE-NOTES | 1 + includes/EditPage.php | 18 +++++++++++++----- includes/Title.php | 16 ++++++++++++++++ languages/Messages.php | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fb6ba7f041..a276998674 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -649,6 +649,7 @@ fully support the editing toolbar, but was found to be too confusing. * Added article size limit, $wgMaxArticleSize * (bug 4974) Don't follow redirected talk page on "new messages" link * (bug 4970) Make category paging limits configurable +* (bug 4535) Warn user when editing CSS or JS subpage of a skin that doesn't exist === Caveats === diff --git a/includes/EditPage.php b/includes/EditPage.php index 1aad75fc1e..47f531148e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -250,7 +250,8 @@ class EditPage { $this->isConflict = false; // css / js subpages of user pages get a special treatment - $this->isCssJsSubpage = $wgTitle->isCssJsSubpage(); + $this->isCssJsSubpage = $wgTitle->isCssJsSubpage(); + $this->isValidCssJsSubpage = $wgTitle->isValidCssJsSubpage(); /* Notice that we can't use isDeleted, because it returns true if article is ever deleted * no matter it's current state @@ -747,12 +748,19 @@ class EditPage { if( wfReadOnly() ) { $wgOut->addWikiText( wfMsg( 'readonlywarning' ) ); - } else if ( $this->isCssJsSubpage and 'preview' != $this->formtype) { - $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' )); - } else if( $wgUser->isAnon() && $this->formtype != 'preview' ) { + } elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) { $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) ); + } else { + if( $this->isCssJsSubpage && $this->formtype != 'preview' ) { + # Check the skin exists + if( $this->isValidCssJsSubpage ) { + $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) ); + } else { + $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) ); + } + } } - + if( $this->mTitle->isProtected( 'edit' ) ) { if( $this->mTitle->isSemiProtected() ) { $notice = wfMsg( 'semiprotectedpagewarning' ); diff --git a/includes/Title.php b/includes/Title.php index d65176e4ba..f2349bc0f5 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1105,6 +1105,22 @@ class Title { function isCssJsSubpage() { return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) ); } + /** + * Is this a *valid* .css or .js subpage of a user page? + * Check that the corresponding skin exists + */ + function isValidCssJsSubpage() { + global $wgValidSkinNames; + return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) ); + } + /** + * Trim down a .css or .js subpage title to get the corresponding skin name + */ + function getSkinFromCssJsSubpage() { + $subpage = explode( '/', $this->mTextform ); + $subpage = $subpage[ count( $subpage ) - 1 ]; + return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) ); + } /** * Is this a .css subpage of a user page? * @return bool diff --git a/languages/Messages.php b/languages/Messages.php index 9db809c70a..ca7d0978c8 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -488,6 +488,7 @@ If you are here by mistake, just click your browser's '''back''' button.", 'usercssjsyoucanpreview' => 'Tip: Use the \'Show preview\' button to test your new CSS/JS before saving.', 'usercsspreview' => '\'\'\'Remember that you are only previewing your user CSS, it has not yet been saved!\'\'\'', 'userjspreview' => '\'\'\'Remember that you are only testing/previewing your user JavaScript, it has not yet been saved!\'\'\'', +'userinvalidcssjstitle' => "'''Warning:''' There is no skin \"$1\". Remember that custom .css and .js pages use a lowercase title, e.g. User:Foo/monobook.css as opposed to User:Foo/Monobook.css.", 'updated' => '(Updated)', 'note' => 'Note:', 'previewnote' => 'This is only a preview; changes have not yet been saved!', -- 2.20.1